package logic

import (
	"context"
	"fmt"
	"wechat/models/mysql"

	"wechat/userpc/internal/svc"
	"wechat/userpc/userpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type LoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic {
	return &LoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *LoginLogic) Login(in *userpc.LoginRequest) (*userpc.LoginResponse, error) {
	// todo: add your logic here and delete this line
	var users mysql.User
	mysql.DB.Where("account=?", users.Account).Find(&users)
	if users.Account == "" {
		return nil, fmt.Errorf("用户不存在,请重新输入")
	}

	if users.Password == in.Password {
		return nil, fmt.Errorf("密码错误,请重新输入")
	}
	return &userpc.LoginResponse{
		Id: int64(users.ID),
	}, nil
}
